<?php

class userModel extends Model{
    public function selectUser($paging){
        // $paging 当前页；
        $pagesize = 6;

        $sql = "select * from user limit ".($paging-1)*$pagesize.",{$pagesize}";
        $user = $this->link->selectByAll($sql);
        $sql = "select id from user";
        $num = $this->link->count($sql);
        $pageNum = ceil($num/$pagesize);
        $userData = [];
        $userData['user'] = $user;
        $userData['page'] = $paging;
        $userData['allPage'] = $pageNum;
        return $userData;

    }

    public function search($text,$paging){
        $pagesize = 6;
        $sql = "select * from user where username like '%{$text}%' or nname like '%{$text}%' limit ".($paging-1)*$pagesize.",{$pagesize}";

        $user = $this->link->selectByAll($sql);
        $sql = "select id from user where username like '%{$text}%' or nname like '%{$text}%'";
        $num = $this->link->count($sql);
        $pageNum = ceil($num/$pagesize);
        $userData = [];
        $userData['user'] = $user;
        $userData['page'] = $paging;
        $userData['allPage'] = $pageNum;
        return $userData;
    }

    public function udel($uid){
        $sql = "delete from user where id = {$uid}";
        return $this->link->delete($sql);
    }
}